package logic

import (
	"campus-trade/campusrpc/campusrpc"
	"campus-trade/campusrpc/internal/svc"
	"campus-trade/models/mysql"
	"context"
	"fmt"
	"strings"

	"github.com/zeromicro/go-zero/core/logx"
)

type PingLunAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPingLunAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLunAddLogic {
	return &PingLunAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PingLunAddLogic) PingLunAdd(in *campusrpc.PingLunAddRequest) (*campusrpc.PingLunAddResponse, error) {
	// todo: add your logic here and delete this line

	var lun mysql.PingLun
	if lun.Name == "物品成色很新" {
		return nil, fmt.Errorf("支持用户发表商品评价内容")
	}

	if strings.Contains(in.Name, "欺诈") || strings.Contains(in.Name, "伪劣") {
		return nil, fmt.Errorf("评价内容中有敏感词")
	}

	lun = mysql.PingLun{
		BookId: in.BookId,
		Name:   in.Name,
	}
	mysql.DB.Debug().Create(&lun)
	return &campusrpc.PingLunAddResponse{
		PingLunId: int64(lun.ID),
	}, nil
}
